package Week3.J0502;

public class 字符串替换 {

    public String formatString (String str, char[] arg) {
        StringBuffer sbr = new StringBuffer();
        int cnt = 0;

        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '%') {
                sbr.append(arg[cnt++]);
                i++;
            }else {
                sbr.append(str.charAt(i));
            }
        }

        if (arg.length > cnt) {
            for (int i = cnt; i < arg.length; i++) {
                sbr.append(arg[i]);
            }
        }
        return sbr.toString();
    }
}
